package com.example.test0.service.imp;

import com.example.test0.MainAlgorithm.MainRecommend;
import com.example.test0.mapper.GoodsMapper;
import com.example.test0.mapper.UserMapper;
import com.example.test0.model.Goods;
import com.example.test0.model.GoodsImfBean;
import com.example.test0.model.UserLike;
import com.example.test0.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GoodsServiceImp implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    public List<Goods> FindAllGoods() {

        return goodsMapper.findAllGoods();
    }

    public List<GoodsImfBean> FindRemGoods(int user_power, String userid) {
        List<GoodsImfBean> ret = new ArrayList<>();

        List<Goods> goods = goodsMapper.findAllGoods();
        List<UserLike> item = goodsMapper.findAllInturn();
        List<UserLike> useritem = goodsMapper.findInturnByUserid(userid);

        if (user_power == 1) {

            MainRecommend recommend = new MainRecommend(goods);
            goods = recommend.VisitorRecommend();
        } else if (user_power == 2) {

            System.out.println("user rem");
            MainRecommend recommend = new MainRecommend(goods, item, useritem);
            goods = recommend.UserRecommend();
        } else if (user_power == 3) {

            System.out.println("admin rem");
        }

        int length = goods.size();
        for (Goods good : goods) {
            GoodsImfBean goodsImfBean =
                    new GoodsImfBean(good.getId(), good.getName(), good.getAddress());
            ret.add(goodsImfBean);
        }

        return ret;
    }
}
